using System;
using Dto;
using Model;
using UnityEngine;
using UnityEngine.UI;

namespace UI
{
    public class LeftStatePanel : StatePanel
    {
        protected override void Awake()
        {
            base.Awake();
            Bind(UIEvent.SET_LEFT_PLAYER_DATA, UIEvent.PLAYER_READY);
        }

        public override void Execute(int eventCode, object message)
        {
            base.Execute(eventCode, message);
            switch (eventCode)
            {
                case UIEvent.SET_LEFT_PLAYER_DATA:
                    this.user = message as Account;
                    break;
                default:
                    break;
            }
        }

        protected override void Start()
        {
            base.Start();
            
                if (Models.GameModel.MatchRoom != null && Models.GameModel.MatchRoom.LeftId != null)
                {
                    this.user = Models.GameModel.MatchRoom.uids[Models.GameModel.MatchRoom.LeftId];
                    if (Models.GameModel.MatchRoom.readyUids.Contains(Models.GameModel.MatchRoom.LeftId))
                    {
                        ReadyState();
                    }
                }
                else
                {
                    setPanelActive(false);
                }
        }

        void Update()
        {
        }
    }
}